using System;
using System.Web.Mvc;

using Plain.Search;
using Plain.DuckTyping;
using Plain.Data;

namespace Plain.Web.Mvc
{
	public static class ViewExtension
	{
		public static ViewResult Add<T> (this ViewResult view, string name, Criteria crit)
		{
			Type typeArg = typeof(T);
			IDaoFactory factory = PlainApplication.Config.DaoFactory;
            object dao = factory.GetMethod<object>("GetDao", typeArg, typeArg.GetProperty("Id").PropertyType).Call();
            var result = dao.CallMethod("Search", crit);
			view.ViewData.Add(name,result);
			return view;
		}
	}
}

